﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Stonecode.Solar.ParticleEngine.Utils
{
    static class NumberGenerator
    {
        private static Random _rand = new Random(1987012);

        public static bool GenerateRandomBool()
        {
            return (_rand.Next(0, 1) != 0);
        }

        public static void GenerateRandomInteger(int low, int high, out int r)
        {
            r = _rand.Next(low, high);
        }
        public static int GenerateRandomInteger(int low, int high)
        {
            return _rand.Next(low, high);
        }
        public static void GenerateRandomDouble(out double d)
        {
            d = _rand.NextDouble();
        }

        public static void GenerateRandomInteger(int baseNum, int range, out int r, int? nullObject)
        {
            r = _rand.Next(baseNum - range, baseNum + range);
        }

        public static void GenerateRandomFloat(float min, float max, out float r)
        {
            if (min == max)
                r = min;
            else
                r = (float)_rand.NextDouble() * (Math.Max(max,min) - Math.Min(max,min)) + min; 
        }

        public static void GenerateRandomFloatWithRange(float baseFloat, float range, out float r)
        {
            GenerateRandomFloat(baseFloat - range, baseFloat + range, out r);
        }

        public static void GenerateRandomVector2(Vector2 min, Vector2 max, out Vector2 r)
        {
            if (min.X > max.X)
                throw new ArgumentException("Max (X) cannot be less than min");
            if (min.Y > max.Y)
                throw new ArgumentException("Max (Y) cannot be less than min");

            r = Vector2.Zero;
            GenerateRandomFloat(Math.Min(min.X, max.X), Math.Max(min.X, max.X), out r.X);
            GenerateRandomFloat(Math.Min(min.Y, max.Y), Math.Max(min.Y, max.Y), out r.Y);
        }
        public static void GenerateRandomVector2WithRange(Vector2 baseVec, float range, out Vector2 r)
        {
            GenerateRandomVector2(baseVec - (Vector2.One * range), baseVec + (Vector2.One * range), out r);
        }

    }
}
